package com.catty.provide.publish;

import java.util.HashMap;
import java.util.Map;

public class ServiceBox {

	private static ServiceBox serviceBox;
	
    private static Map<String,Object> map_objs = new HashMap<String,Object>();  

	public static Map<String,String> serviceMap = new HashMap<String,String>();
	
	private ServiceBox(){
		
	}
	
	public synchronized static ServiceBox getServiceBoxInstance(){
		if(serviceBox==null){
			serviceBox = new ServiceBox();
		}
		return serviceBox;
	}
	
	public  void registerService(Map<String,String> serviceMap){
		ServiceBox.serviceMap = serviceMap;
	}
	
	public  void registerService(String name,String target){
		serviceMap.put(name, target);
	}
	public String getServiceTarget(String interfaceName){
		if(serviceMap.containsKey(interfaceName)){
			return serviceMap.get(interfaceName);
		}
		return null;
	}
	
	public Object getServiceObject(String key){
		if(map_objs.containsKey(key)){
			return map_objs.get(key);
		}
		return null;
	}
	
	public boolean registerServiceObject(String key,Object object){
		
		map_objs.put(key, object);
		if(map_objs.containsKey(key)){
			return true;
		}
		return false;
	}
	public String publishServiceListString(){
		if(serviceMap==null || serviceMap.size()==0){
			return "";
		}
		StringBuffer sb = new StringBuffer();
		for(String key:serviceMap.keySet()){
			sb.append(key);
			sb.append(",");
		}
		return sb.toString();
	}
}
